package cn.swust.designpatternlearningplatform.dao.sql;

import cn.swust.designpatternlearningplatform.domain.entity.About;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.jdbc.SQL;

import java.time.LocalDateTime;
import java.util.List;

public class AboutDaoSql {
   public String add(About about){
       String content = about.getContent();
       String title = about.getTitle();
       LocalDateTime time = about.getTime();
       String nav = about.getNav();
       Integer isFront = about.getIsFront();
       return new SQL(){
            {
                INSERT_INTO("about");
                VALUES("nav","#{nav}");
                VALUES("title","#{title}");
                VALUES("content","#{content}");
                VALUES("time","#{time}");
                VALUES("is_front","#{isFront}");
            }
        }.toString();
    }

    public String update(About about){
           String content = about.getContent();
           String title = about.getTitle();
           LocalDateTime time = about.getTime();
           String nav = about.getNav();
           Integer isFront = about.getIsFront();
           Integer id = about.getId();
           return new SQL(){
               {
                   UPDATE("about");
                   SET("content=#{content}","title=#{title}","time=#{time}","nav=#{nav}","is_front=#{isFront}");
                   WHERE("id=#{id}");
               }
           }.toString();
    }

    public  String delete(Integer integer){
       return new SQL(){
           {
               DELETE_FROM("about");
               WHERE("id=#{integer}");
           }
       }.toString();
    }

       public String selectAll(){
           return new SQL(){
               {
                   SELECT("*");
                   FROM("about");
               }
           }.toString();
       }
}
